﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using LetiLib.Database;
using LetiLib.Data;

namespace LedCenter
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            /*
            XmlDatabase database = XmlDatabase.Instance;

            List<LETIPage> listplaylist = database.getPagesData();
            int count = 0;
            foreach (LETIPage playlist in listplaylist)
            {
                playlist.save(count+".page");
                count++;
                Debug.WriteLine(playlist.ToString());
            }
            return;
            */
            try
            {
                // Create working folder
                //CreateWorkingFolder();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                XmlDatabase database = XmlDatabase.Instance;
                database.DATABASE_NAME = System.IO.Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\DB\\LedCenter.xml";
                Application.Run(new MainForm());
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                MessageBox.Show("LedCenter quit unexpectedly!\n" + ex.Message, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private static void CreateWorkingFolder()
        {
            //return;
            string exeDirectoryPath = System.IO.Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().Location);
            string logPath = exeDirectoryPath + "\\Logs";
            if (!System.IO.Directory.Exists(logPath))
            {
                System.IO.Directory.CreateDirectory(logPath);
            }
        }
    }
}
